-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoomEditor.java
More file actions
91 lines (81 loc) · 2.45 KB
/
Copy pathRoomEditor.java
File metadata and controls
91 lines (81 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Tool to help with designing room layouts. Draw out room layout and press 'e' to save (*changed!)-
* String representation of layout will be printed to terminal so you can copy and paste.
*
* @author Angela Wang
* @version June 4 2025
*/
public class RoomEditor extends World
{
private Board room;
private char newType;
private boolean isMousePressed;
private Cursor mouse;
/**
* Constructor for objects of class RoomEditor.
*
*/
public RoomEditor()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1024, 768, 1, false);
room = new Board();
addObject(room, 0, 0);
room.display();
mouse = new Cursor(false);
addObject(mouse, 0, 0);
}
//test
public void act(){
//press key to set tile type/save
if (Greenfoot.isKeyDown("g")){
newType = 'g';
} else if (Greenfoot.isKeyDown("q")){
newType = 'q';
} else if (Greenfoot.isKeyDown("w")){
newType = 'w';
} else if (Greenfoot.isKeyDown("u")){
newType = 'u';
} else if (Greenfoot.isKeyDown("b")){
newType = 'b';
} else if (Greenfoot.isKeyDown("f")){
newType = 'f';
} else if (Greenfoot.isKeyDown("s")){
newType = 's';
} else if (Greenfoot.isKeyDown("e")){
newType = 'e';
} else if (Greenfoot.isKeyDown("Enter")){
System.out.println("Saved.");
System.out.println(room.getLayout());
}
//if user presses mouse, start drag
if (Greenfoot.mousePressed(null)){
isMousePressed = true;
} else if (Greenfoot.mouseClicked(null)){
//if user lets go of mouse, end drag
isMousePressed = false;
}
}
/**
* Returns the type of Tile user is drawing
* @return char
*/
public char getNewType(){
return newType;
}
/**
* Returns true if mouse is being dragged
* @return boolean
*/
public boolean getIsMousePressed(){
return isMousePressed;
}
/**
* Returns the world's Cursor so Tiles know if they are being moved over by the mouse
* @return Cursor
*/
public Cursor getCursor(){
return mouse;
}
}